
import CryptoJS from 'crypto-js'


/**加密 */
 function encryptAes (key,iv,data){
    var key = CryptoJS.enc.Latin1.parse(key);
    var iv = CryptoJS.enc.Latin1.parse(iv);
    let encryData=CryptoJS.AES.encrypt(JSON.stringify(data), key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.ZeroPadding
      }).toString()
    return encryData;
}

/**解密 */
 function decryptAes (key,iv,data){
    var key = CryptoJS.enc.Latin1.parse(key);
    var iv = CryptoJS.enc.Latin1.parse(iv);
    let decryptData=JSON.parse(
        CryptoJS.AES.decrypt(data, key, {
          iv: iv,
          padding: CryptoJS.pad.ZeroPadding
        }).toString(CryptoJS.enc.Utf8))
    return decryptData;
}

export{
  encryptAes,
  decryptAes
}